﻿#ifndef JZCO_NET_WORK_H
#define JZCO_NET_WORK_H

#include <QNetworkReply>
#include <QTcpSocket>
#include <QTcpServer>
#include "JZCoCoroutine.h"

class JZCoNetWorkManager
{
public:
		
};

class JZCoNetworkReply
{
public:
	JZCoNetworkReply(QNetworkReply* reply);

	void waitFinish();
	QByteArray read();
	QByteArray readToEnd();

protected:
	QNetworkReply* m_reply;
};

class JZCoTcpSocket
{
public:
	JZCoTcpSocket();
	JZCoTcpSocket(QTcpSocket* socket);

	bool isNull();
	bool connectToHost(const QString&addr, quint16 port);
	void disconnectFromHost();    

    bool waitForReadyRead(int timeout);
	QByteArray read(int size);
	QByteArray readAll();
	qint64 write(const QByteArray& buffer);

	QTcpSocket* socket();

protected:
	QTcpSocket* m_socket;
};

class JZCoTcpServer
{
public:
	JZCoTcpServer(QTcpServer* server);

	JZCoTcpSocket accept();

protected:
	QTcpServer* m_server;
};

#endif // !JZCO_NET_WORK_H
